package com.parkinglot.extend.orderextend;

import com.parkinglot.pojo.GarageMonthConfig;
import com.parkinglot.pojo.Order;
import com.parkinglot.service.GarageMonthConfigService;
import com.parkinglot.service.GarageService;
import com.parkinglot.util.DateUtils;
import com.parkinglot.vo.GaragequeryVo;
import com.parkinglot.vo.OrderqueryVo;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.Date;

public class OrderExtend {
    @Resource
   private GarageMonthConfigService garageMonthConfigService;
    @Resource
    private GarageService garageService;
    /**
     * 订单计算价格
     */
    public  OrderqueryVo drdersettlement(OrderqueryVo orderqueryVo, Order order,GaragequeryVo garagequeryVo,GarageMonthConfig garageMonthConfig){
        String garageid=order.getGarageid();
        //查询停车场月票价格
      /*  GarageMonthConfig garageMonthConfig= garageMonthConfigService.queryAll(garageid);
        GaragequeryVo garagequeryVo = garageService.queryBygaragecode(garageid);//查询停车场收费标准*/
        String firsttime="";
        try {
            firsttime=orderqueryVo.getParkingTime();

            String endtime= DateUtils.getFormatDate(new Date());
            int hours=  DateUtils.sjc(firsttime, endtime);//hours 分钟数
            if(hours<60){
                order.setPayMoney(garagequeryVo.getBanhour());
                orderqueryVo.setPayMoney(order.getPayMoney());
            }else{
                BigDecimal money = garagequeryVo.getOnehour();
                BigDecimal banmomey=garagequeryVo.getBanhour();
                int xiaoshi=hours/60; //hours是分钟数  除60  换算小时
                int yushu=hours%60;  //取余数  余数大于30分钟  就加上半小时金额
                BigDecimal xiaoshis=BigDecimal.valueOf(xiaoshi);
                BigDecimal yushus=BigDecimal.valueOf(yushu);
            //    BigDecimal hour = BigDecimal.valueOf(hours);
                BigDecimal total = money.multiply(xiaoshis);

                total=yushu>30?  total.add(money):  total.add(banmomey);
                order.setPayMoney(total);
                orderqueryVo.setPayMoney(total);
            }
            orderqueryVo.setParkingTimesjc(DateUtils.getParse(orderqueryVo.getParkingTime()).getTime());
            if(garageMonthConfig != null) {
                orderqueryVo.setMonthvipmoney(garageMonthConfig.getMonthvipmoney());
            }

        } catch (ParseException e) {
            e.printStackTrace();
        }
        return orderqueryVo;
    }
    public  OrderqueryVo drdersettlement(String banhour, String onehour,String firsttime,String endtime) throws ParseException {
        int hours=  DateUtils.sjc(firsttime, endtime);


        return null;
    }
    }
